﻿using Engine;
using Engine.Graphics;

namespace Game
{
	public class 十亿伏特万用板 : RotateableMountedGVElectricElementBlock
	{
		public const int Index = 32;
		public readonly Texture2D texture;

		public 十亿伏特万用板() : base("Models/GigavoltGates","AndGate",0.5f) => texture = ContentManager.Get<Texture2D>("Textures/万用板");

		public override GVElectricElement CreateGVElectricElement(SubsystemGVElectricity subsystemGVElectricity,int value,int x,int y,int z) => new 万用板电路元素(subsystemGVElectricity,new CellFace(x,y,z,GetFace(value)));

		public override GVElectricConnectorType? GetGVConnectorType(SubsystemTerrain terrain,int value,int face,int connectorFace,int x,int y,int z)
		{
			int data = Terrain.ExtractData(value);
			if(GetFace(value) == face)
			{
				GVElectricConnectorDirection? connectorDirection = SubsystemGVElectricity.GetConnectorDirection(GetFace(value),GetRotation(data),connectorFace);
				if(connectorDirection == GVElectricConnectorDirection.Right
					|| connectorDirection == GVElectricConnectorDirection.Left
					|| connectorDirection == GVElectricConnectorDirection.Bottom
					|| connectorDirection == GVElectricConnectorDirection.In)
				{
					return GVElectricConnectorType.Input;
				}
				if(connectorDirection == GVElectricConnectorDirection.Top)
				{
					return GVElectricConnectorType.Output;
				}
			}
			return null;
		}
		public override void GenerateTerrainVertices(BlockGeometryGenerator generator,TerrainGeometry geometry,int value,int x,int y,int z)
		{//在地图上画
			int num = Terrain.ExtractData(value) & 0x1F;
			generator.GenerateMeshVertices(
				this,
				x,
				y,
				z,
				m_blockMeshes[num],
				Color.White,
				null,
				geometry.GetGeometry(texture).SubsetOpaque
			);
			GenerateGVWireVertices(
				generator,
				value,
				x,
				y,
				z,
				GetFace(value),
				m_centerBoxSize,
				Vector2.Zero,
				geometry.SubsetOpaque
			);
			generator.GenerateWireVertices(
				value,
				x,
				y,
				z,
				GetFace(value),
				m_centerBoxSize,
				Vector2.Zero,
				geometry.SubsetOpaque
			);
		}
		public override void DrawBlock(PrimitivesRenderer3D primitivesRenderer,int value,Color color,float size,ref Matrix matrix,DrawBlockEnvironmentData environmentData)
		{//在物品栏和背包等画
			BlocksManager.DrawMeshBlock(
				primitivesRenderer,
				m_standaloneBlockMesh,
				texture,
				color,
				2f * size,
				ref matrix,
				environmentData
			);
		}

	}
}